package com.wpy.auditlog.util;

import com.alibaba.fastjson.JSONObject;
import com.wpy.auditlog.config.AuditLogConfig;
import com.wpy.auditlog.param.AuditParam;
import org.slf4j.LoggerFactory;

import org.slf4j.Logger;
import org.springframework.util.ObjectUtils;

public class AuditLogger {
    private  static final Logger logger = LoggerFactory.getLogger(AuditLogger.class);
    private static AuditLogConfig auditLogConfig;

    public static void initAuditLogConfig(AuditLogConfig config) {
        auditLogConfig = config;
    }
    public static void audit(AuditParam auditParam){
        if (auditLogConfig == null || !auditLogConfig.isAuditLogEnabled()) {
            logger.warn("审计日志无输出: 日志功能未开启");
            return;
        }

        if (ObjectUtils.isEmpty(auditParam)) {
            logger.warn("审计日志无输出: AuditParam为空");
            return;
        }
        // AuditParam简单脱敏处理
        logger.info(JSONObject.toJSONString(auditParam));
    }
}
